package topo.frame;

import com.zhtelecom.common.base.MyLog;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import topo.mibobject.MibSWRunCpuAndMemEntry;
import topo.table.ObjectTableDesc;

public class RunSWCpuAndMemTableDesc implements ObjectTableDesc {
    public Object[] getcolumnNames() {
        String[] cols = { "进程ID", "进程名称", "CPU时间", "内存", "启动路径", "运行状态", "表OID索引值" };
        return cols;
    }

    public Object[] getRowDatas(Object obj) {
        MibSWRunCpuAndMemEntry table = (MibSWRunCpuAndMemEntry) obj;
        Object[] viDatas = { new Integer(table.getHrSWRunIndex()), table.getHrSWRunName(), getCpuDisplay(table.getHrSWRunPerfCPU()), getMemDiaplay(table.getHrSWRunPerfMem()), table.getHrSWRunPath(), getRunStatus(table.getHrSWRunStatus()), table.getIndex() };
        return viDatas;
    }

    public String getRunStatus(int runStatus) {
        String value = "";
        switch (runStatus) {
            case 1:
                value = "正在运行";
                break;
            case 2:
                value = "准备运行";
                break;
            case 3:
                value = "不可运行";
                break;
            case 4:
                value = "失效";
        }

        return value;
    }

    public String getCpuDisplay(int cpu) {
        try {
            int sumSeconds = cpu / 100;
            int days = sumSeconds / 86400;
            int remainSeconds = sumSeconds % 86400;
            SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
            Date date = new Date(remainSeconds * 1000 - format.getTimeZone().getRawOffset());
            String value = "";
            if (days > 0) {
                value = value + days + "天 ";
            }
            return value + format.format(date);
        } catch (Exception e) {
            MyLog.err(cpu + "转换成CPU时间出错" + e.getMessage());
            e.printStackTrace();
        }
        return "转换出错";
    }

    public String getMemDiaplay(int mem) {
        NumberFormat format = NumberFormat.getIntegerInstance(Locale.US);
        return format.format(mem) + " K";
    }

    public Class getTableObjectClass() {
        return MibSWRunCpuAndMemEntry.class;
    }
}